<template>
	<div>
		<a-row class="mb-2">
			<a-col span="20">
				<a-space>
					<span>请输入文件名称：</span>
					<a-input v-model:value="props.componentConfig.fileName"></a-input>
				</a-space>
			</a-col>
		</a-row>
		<a-row>
			<a-col span="24">
				<ParamDefine
					v-if="props.componentConfig?.input"
					:params="props.componentConfig.input"
					:isViewBasicFieldFlag="false"
					:isViewArrayFlag="false"
					:isAddColumnFlag="false"
					:isActionColumnFlag="false"
					:isUpdateColumnFlag="false"
					:jsonEditorFlag="false"
					:isUpdateDefaultValueFlag="false"
					:defaultValueFlag="false"
					:isRemoveColumnFlag="false"
					:isAddChildrenColumnFlag="false"
					:isMappingColumnFlag="false"
					ref="left"
				></ParamDefine>
			</a-col>
		</a-row>
	</div>
</template>
<script setup>
import {onMounted, ref, watch, toRaw, inject, getCurrentInstance} from 'vue'
import processVersionContentApi from '@/api/process/processVersionContentApi'
import ParamDefine from "@/views/restapi/ParamDefine.vue";

const defaultConfig = () => {
	return {
		input: {
			params: [],
			basicTypeFlag: false,
			isArrayFlag: false,
			isActionColumnFlag: false,
			isMappingColumnFlag: false,
			isAddColumnFlag: false,
			isUpdateColumnFlag: false,
			jsonEditorFlag: false
		},
		fileName: ""
	}
}

const props = defineProps(['componentConfig', 'id', 'nodeId', 'frontFile'])

// const isArrayFlag = ref(false);
const left = ref()

onMounted(() => {
	if (!hasProperties(props.componentConfig)) {
		const c = defaultConfig()
		props.componentConfig.input = c.input
		props.componentConfig.fileName = c.fileName
	}

	queryInput()
})

const hasProperties = (obj) => {
	if (!obj) {
		return false
	}

	return JSON.stringify(obj) != '{}'
}

const queryInput = async () => {
	const c = await getInputDefine()
	if (c) {
		const cb = left.value.repairJson(c)
		props.componentConfig.input = cb
	}
}

const getInputDefine = async () => {
	// const versionId = props.input.versionId
	// let resource = props.input.resource

	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentInputDefine({
		id: props.id,
		frontFile: props.frontFile,
		stepCode: props.nodeId
	})
	return read
}
</script>
<style scoped></style>
